package dao

import (
	"gitee.com/gopher2011/mbt"
	_ "github.com/go-sql-driver/mysql"
	"sync"
)

var (
	Once   sync.Once   // 这个对象可以全局使用。
	engine *mbt.Engine // 这个对象只能在dao层使用。
)

const (
	MaxOpenConn = 10
	MaxIdleConn = 5
	DSN         = "root:root@tcp(127.0.0.1:3306)/mall?charset=utf8mb4&parseTime=True&loc=Local"
	DriverName  = "mysql"
)

func init() {
	Once.Do(
		func() {
			cfg := &mbt.Config{
				DriverName:  DriverName,
				DSN:         DSN,
				MaxIdleConn: MaxIdleConn,
				MaxOpenConn: MaxOpenConn,
			}
			engine = mbt.New(cfg)
			h := Init()
			g := engine.FilePath("./app/dao/xml").H(h)
			g.Run()
		},
	)
}
func Init() map[interface{}]interface{} {
	h := mbt.H{
		&CmsHelpDao:                             &CmsHelp{},                             //
		&CmsHelpCategoryDao:                     &CmsHelpCategory{},                     //
		&CmsMemberReportDao:                     &CmsMemberReport{},                     //
		&CmsPreferenceAreaDao:                   &CmsPreferenceArea{},                   //
		&CmsPreferenceAreaProductRelationDao:    &CmsPreferenceAreaProductRelation{},    //
		&CmsSubjectDao:                          &CmsSubject{},                          //
		&CmsSubjectCategoryDao:                  &CmsSubjectCategory{},                  //
		&CmsSubjectCommentDao:                   &CmsSubjectComment{},                   //
		&CmsSubjectProductRelationDao:           &CmsSubjectProductRelation{},           //
		&CmsTopicDao:                            &CmsTopic{},                            //
		&CmsTopicCategoryDao:                    &CmsTopicCategory{},                    //
		&CmsTopicCommentDao:                     &CmsTopicComment{},                     //
		&OmsCartItemDao:                         &OmsCartItem{},                         //
		&OmsCompanyAddressDao:                   &OmsCompanyAddress{},                   //
		&OmsOrderDao:                            &OmsOrder{},                            //
		&OmsOrderItemDao:                        &OmsOrderItem{},                        //
		&OmsOrderOperateHistoryDao:              &OmsOrderOperateHistory{},              //
		&OmsOrderReturnApplyDao:                 &OmsOrderReturnApply{},                 //
		&OmsOrderReturnReasonDao:                &OmsOrderReturnReason{},                //
		&OmsOrderSettingDao:                     &OmsOrderSetting{},                     //
		&PmsBrandDao:                            &PmsBrand{},                            //
		&PmsCommentDao:                          &PmsComment{},                          //
		&PmsCommentReplayDao:                    &PmsCommentReplay{},                    //
		&PmsFreightTemplateDao:                  &PmsFreightTemplate{},                  //
		&PmsMemberPriceDao:                      &PmsMemberPrice{},                      //
		&PmsProductDao:                          &PmsProduct{},                          //
		&PmsProductAttributeDao:                 &PmsProductAttribute{},                 //
		&PmsProductAttributeCategoryDao:         &PmsProductAttributeCategory{},         //
		&PmsProductAttributeValueDao:            &PmsProductAttributeValue{},            //
		&PmsProductCategoryDao:                  &PmsProductCategory{},                  //
		&PmsProductCategoryAttributeRelationDao: &PmsProductCategoryAttributeRelation{}, //
		&PmsProductFullReductionDao:             &PmsProductFullReduction{},             //
		&PmsProductLadderDao:                    &PmsProductLadder{},                    //
		&PmsProductOperateLogDao:                &PmsProductOperateLog{},                //
		&PmsProductVerifyRecordDao:              &PmsProductVerifyRecord{},              //
		&PmsSkuStockDao:                         &PmsSkuStock{},                         //
		&SmsCouponDao:                           &SmsCoupon{},                           //
		&SmsCouponHistoryDao:                    &SmsCouponHistory{},                    //
		&SmsCouponProductCategoryRelationDao:    &SmsCouponProductCategoryRelation{},    //
		&SmsCouponProductRelationDao:            &SmsCouponProductRelation{},            //
		&SmsFlashPromotionDao:                   &SmsFlashPromotion{},                   //
		&SmsFlashPromotionLogDao:                &SmsFlashPromotionLog{},                //
		&SmsFlashPromotionProductRelationDao:    &SmsFlashPromotionProductRelation{},    //
		&SmsFlashPromotionSessionDao:            &SmsFlashPromotionSession{},            //
		&SmsHomeAdvertiseDao:                    &SmsHomeAdvertise{},                    //
		&SmsHomeBrandDao:                        &SmsHomeBrand{},                        //
		&SmsHomeNewProductDao:                   &SmsHomeNewProduct{},                   //
		&SmsHomeRecommendProductDao:             &SmsHomeRecommendProduct{},             //
		&SmsHomeRecommendSubjectDao:             &SmsHomeRecommendSubject{},             //
		&UmsAdminDao:                            &UmsAdmin{},                            //
		&UmsAdminLoginLogDao:                    &UmsAdminLoginLog{},                    //
		&UmsAdminPermissionRelationDao:          &UmsAdminPermissionRelation{},          //
		&UmsAdminRoleRelationDao:                &UmsAdminRoleRelation{},                //
		&UmsGrowthChangeHistoryDao:              &UmsGrowthChangeHistory{},              //
		&UmsIntegrationChangeHistoryDao:         &UmsIntegrationChangeHistory{},         //
		&UmsIntegrationConsumeSettingDao:        &UmsIntegrationConsumeSetting{},        //
		&UmsMemberDao:                           &UmsMember{},                           //
		&UmsMemberLevelDao:                      &UmsMemberLevel{},                      //
		&UmsMemberLoginLogDao:                   &UmsMemberLoginLog{},                   //
		&UmsMemberMemberTagRelationDao:          &UmsMemberMemberTagRelation{},          //
		&UmsMemberProductCategoryRelationDao:    &UmsMemberProductCategoryRelation{},    //
		&UmsMemberReceiveAddressDao:             &UmsMemberReceiveAddress{},             // 收货地址表
		&UmsMemberRuleSettingDao:                &UmsMemberRuleSetting{},                //
		&UmsMemberStatisticsInfoDao:             &UmsMemberStatisticsInfo{},             // 会员统计信息
		&UmsMemberTagDao:                        &UmsMemberTag{},                        //
		&UmsMemberTaskDao:                       &UmsMemberTask{},                       //
		&UmsMenuDao:                             &UmsMenu{},                             //
		&UmsPermissionDao:                       &UmsPermission{},                       //
		&UmsResourceDao:                         &UmsResource{},                         //
		&UmsResourceCategoryDao:                 &UmsResourceCategory{},                 //
		&UmsRoleDao:                             &UmsRole{},                             // 用户角色表
		&UmsRoleMenuRelationDao:                 &UmsRoleMenuRelation{},                 // 角色与菜单的关系表
		&UmsRolePermissionRelationDao:           &UmsRolePermissionRelation{},           //
		&UmsRoleResourceRelationDao:             &UmsRoleResourceRelation{},             // 角色&lt;--&gt;资源表
	}
	return h
}
